using System;
using System.Collections.Generic;
using ViScript.Core.Argument;
using ViScript.Core.Utils;

namespace ViScript.Core.ParameterRules
{
    public class CompositeParameterRule : IParameterRule
    {
        private readonly Dictionary<Type, IParameterRule> parameterRules = new Dictionary<Type, IParameterRule>();

        public IArgument Parse(Type type, IText text, ISentence sentence)
        {
            if (!parameterRules.ContainsKey(type))
            {
                return UnrecognizedArgument.UNRECOGNIZED_ARGUMENT;
            }
            return parameterRules[type].Parse(type, text, sentence);
        }

        public void Add(Type type, IParameterRule parameterRule)
        {
            parameterRules.Add(type, parameterRule);
        }
    }
}